require "arknights/utils"

-- home按钮
local shortcut_button = {x=400, y=55, c=0xD8D8D8}
-- 好友界面元素
local friend_list = {x=95, y=350, c=0x313131} -- 点击后的好友列表hint
local visit_first = {x=1510, y=236, c=0xffffff} -- 第一个好友的访问按钮

-- 别人的界面元素
local next_doc_tag = {x=1820, y=995, c=0xd15806}
local no_next_tag = {x=1820, y=995, c=0x2c2c2c}
local exit_confirm = {x=1490, y=760, c=0x791616}

local auto_visit = {}

auto_visit.run = function()
    waitForColor(friend_list, 500, 
        function ()
            qcRandTap(friend_list, 15, 300)
        end
    )
    waitForColor(visit_first, 500)
    waitWhileColor(visit_first, 500, 
        function ()
            qcRandTap(visit_first, 15, 300)
        end    
    )
    waitForColor(shortcut_button, 1000)

    while true do
        local no_more_flag = false
        waitForColor(next_doc_tag, 1000,
            function ()
                -- expire_counter = expire_counter - 1
                -- if expire_counter == 0 then
                --     return false
                -- end
                if qcIsColor(no_next_tag) then
                    no_more_flag = true
                    return false
                end
            end  
        )
        if no_more_flag then
            qcKeyBack(1000)
            waitWhileColor(exit_confirm, 300, 
                function ()
                    qcRandTap(exit_confirm, 20 ,300)
                end    
            )
            break
        else
            qcRandTap(next_doc_tag, 20, 500)
        end
    end
end

-- auto_visit.run()
if __name__ == 'main' then    
    return auto_visit
else
    init(1)
    auto_visit.run()
end